package cn.lyn4ever.cataccount.service.impl;

import cn.lyn4ever.cataccount.entity.AnalysisPoperty;
import cn.lyn4ever.cataccount.entity.Bill;
import cn.lyn4ever.cataccount.entity.Property;
import cn.lyn4ever.cataccount.mapper.PropertyMapper;
import cn.lyn4ever.cataccount.service.PropertyService;
import cn.lyn4ever.common.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Property)表服务实现类
 *
 * @author makejava
 * @since 2019-09-21 16:56:57
 */
@Service("propertyService")
public class PropertyServiceImpl implements PropertyService {

    @Resource
    private PropertyMapper propertyMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Property queryById(Integer id) {
        return null;
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Property> queryAllByLimit(int offset, int limit) {
        return null;
    }

    /**
     * 新增数据
     *
     * @param property 实例对象
     * @return 实例对象
     */
    @Override
    public R insert(Property property) {
        int line = propertyMapper.insertOne(property);
        if(line>0)
            return R.sucess();
        return R.fail();
    }

    /**
     * 修改数据
     *
     * @param property 实例对象
     * @return 实例对象
     */
    @Override
    public Property update(Property property) {
        return null;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return false;
    }

    /**
     * 查询用户财产列表
     *
     * @return
     */
    @Override
    public R listAll(Property property) {

        List<Property> list = propertyMapper.getList(property);

        //算出财产统计
//        AnalysisPoperty analysisPoperty=  propertyMapper.getAnalysisProperty(property);


        if (null != list && list.size() > 0)
            return R.sucess("查询成功", list);
        return R.fail();
    }

    /**
     * 查询财产统计
     *
     * @param property
     * @return
     */
    @Override
    public R getAnalysisProperty(Property property) {
        AnalysisPoperty analysisProperty = propertyMapper.getAnalysisProperty(property);

        if (null != analysisProperty) {
            return R.sucess("查询成功", analysisProperty);
        }
        return R.fail("没有查询出来结果");
    }

    /**
     * 当删除账单时，修改用户财产
     *
     * @param bill
     * @return
     */
    @Override
    public R updateWhenDelBill(Bill bill) {
        String consumetype = bill.getConsumetype();
        if (consumetype.equals("1")) {
            bill.setConsumetype("0");
        } else if (consumetype.equals("0")) {
            bill.setConsumetype("1");
        }
        int line = propertyMapper.updateOneByBill(bill);
        if (line > 0)
            return R.sucess();

        return R.fail();
    }

    /**
     * 根据赎单修改用户财产
     *
     * @param bill
     */
    @Override
    public R updateOneByBill(Bill bill) {
        int line = 0;
            line = propertyMapper.updateOneByBill(bill);

        if (line > 0)
            return R.sucess();
        return R.fail();
    }



}